// 为啥要分模块开发
// 利于团队开发
const express = require('express');
const router = express.Router();

router.get('/', function(req, res, next){
  console.log('这是根1');
  next();
  console.log('这是根3');
  res.send({msg: '根'});
});

router.get('/', function(req, res, next){
  console.log('这是根2');
  // next();
  console.log('这是根4');
});

// api 数据接口
router.post('/user/login', function(req, res){
  console.log('用户登录');
  // jwt 
  let token = '11223345566777888888';
  res.send({msg: '用户登录成功', code:200, token: token});
});

router.get('/user/friends', function(req, res){
  let token = req.query.token;
  if (!token) {
    res.send({msg: '非法用户登录', code: 201});
    return;
  }
  let friends = [
    {name: 'Tom', age: 18},
    {name: 'Jary', age: 18},
    {name: 'Jack', age: 20},
  ];
  res.send({msg:'获取用户列表成功', code:200, data:friends});
});

module.exports = router;
